* STATA Do file for Chapter 8, Mark R. Beissinger, The Revolutionary City  
version 14
clear all
set more off
log using Logfiles\chapter8.log, replace
* ============================================================================
* STATISTICAL RESULTS APPEARING IN CHAPTER 8
* STATA Do file for Chapter 8  
* Results reported in Chapter 8  
* Author: Mark R. Beissinger  
* Date:  January 2022  
* Princeton, NJ 
* =============================================================================
* BEFORE RUNNING, YOU MUST SET THE DEFAULT PATH FOR WHERE THE DATA
*   FILES RESIDE
* =============================================================================
* Before running, you must download the following package for STATA for running 
*    Brant command, from spost13_ado from https://jslsoc.sitehost.iu.edu/statatests
*    switchcopula from http://www.stata-journal.com/software/sj13-3
* =============================================================================
* The following datafiles are used in this chapter:
*   Data set of revolutionary episodes--revolutionaryeps.dta
* =============================================================================
* Output produced:  Logfiles\chapter8.log
* =============================================================================

* =============================================================
* LEVELS OF VIOLENCE IN SOCIAL VS. OTHER REVOLUTIONARY EPISODES
* =============================================================
clear
use revolutionaryeps.dta
ttest totaldeaths if startyear>1899, by(leftist)
centile totaldeaths if startyear>1899 & success==1 & leftist==1, centile(60)
sum totaldeaths if startyear>1899 & success==1 & leftist==1, detail

* Median levels of violence in other revolutions, by success
sum totaldeaths if startyear>1899 & success==0 & leftist==0, detail
sum totaldeaths if startyear>1899 & success==1 & leftist==0, detail
* All revolutionary episodes
tab deathscat success if startyear>1899, col

* ================================================
* TABLE 8.1, DEATH CATEGORIES ACROSS TIME PERIODS
* ================================================
tab deathscat timeperiod, col

* =====================================================
* TOTAL DEATHS IN REVOLUTIONARY EPISODES BY TIME PERIOD
* =====================================================
table timeperiods if startyear>1899, c(sum totaldeaths) format(%13.0f)
* Calculate difference, prorating Cold War deaths by number of years (35) compared to post-Cold War (30)

* ====================================
* DURATION OF EPISODES WITH CIVIL WARS
* ====================================
sum monthsduration if civilwar==1 & startyear>1899, detail

* =================================================================
* RESPONSIBILITY OF CIVIL WARS FOR DEATHS IN REVOLUTIONARY EPISODES
* =================================================================
table civilwar if startyear>1899, c(sum totaldeaths)
tab deathscat civilwar if startyear>1899, col

* ===========================================================================
* FIGURE 8.1, RELATIONSHIP BETWEEN TIME AND DEATHS IN REVOLUTIONARY EPIOSDES
*   INVOLVING CIVIL WARS
* ===========================================================================
glm totaldeaths c.newstartyr##c.newstartyr if civilwar==1 & startyear>1899, family(gamma) link(log) vce(robust)
margins, at(newstartyr=(0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115))


* ===========================================
* TESTING FOR BEST COPULA FOR SWITCHING MODEL
* ===========================================
* Program for identifying cupolas
* Set specification
* See below--Tables 8.2, 8.3, and 8.4 for selection of model specifications
* Define x0
local x0 = " success newpolitymin1 urbancivic newgdppcthl urbandum "
* Define x1
local x1 = "lnmonthsdur urbpercbefrev success "
* Define xs
local xs = "urbandum leftist ethnicorder "
* Define y0
local y0 = "lndeaths "
* Define y1
local y1 = "lndeaths "
* Define s
local s = "civilwar "

* Program
* the benchmark model under the joint normality
quietly switchcopula (`y0' = `x0') (`y1' = `x1'), select(`s' = `xs') iterate(75)
* after the copula estimation
predict xb0_0, xb0
predict xb1_0, xb1
predict cll0, cll
local llmax = `e(ll)'
display `llmax'
* Program for finding best combination of cupolas
* Finding the best-fitting copulas by using two loops
* First loop
foreach copula in list product gaussian fgm plackett amh frank clayton gumbel joe {
capture switchcopula (`y0' = `x0') (`y1' = `x1'), select(`s' = `xs') copula0(gaussian) copula1(`copula') iterate(75)
if `e(ll)' > `llmax' {
local llmax = `e(ll)'
local bestcop1 = "`copula'"
}
}
* Second loop
foreach copula in list product gaussian fgm plackett amh frank clayton gumbel joe {
capture switchcopula (`y0' = `x0') (`y1' = `x1'), select(`s' = `xs') copula0(`copula') copula1(`bestcop1') iterate(75)
if `e(ll)' > `llmax' {
local llmax = `e(ll)'
local bestcop0 = "`copula'"
}
capture switchcopula (`y0' = `x0') (`y1' = `x1'), select(`s' = `xs') copula0(`bestcop0') copula1(`bestcop1') iterate(75)
estimates store best_model
}
* display the estimation result of the selected copula
estimates replay best_model
display "`bestcop0'" " `bestcop1'"
drop xb0_0 xb1_0 cll0 _est_best_model
* Best copulas were Clayton/FGM

* =================================================================
* INFORMATION CRITERION TESTS AND VUONG TEST ON CLAYTON-FGM COPULA 
*   SWITCHING REGRESSION MODEL VS. JOINT NORMAL
* =================================================================
* Joint normal model
switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur success urbpercbefrev) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) 
estat ic
predict cll0 if e(sample), cll
* Copula model with highest log-likelihood (clayton-fgm)
switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur success urbpercbefrev) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
estat ic
predict cll1 if e(sample), cll
quietly generate dll = cll1 - cll0
regress dll
* RESULT:  AIC and BIC of the Clayton-FGM copula model are significantly lower and statistically preferred to the joint normal model.
* 	   Vuong test is statistically significant, confirming superiority of copula model
drop cll1 cll0 dll

* ============================================================================
* INFORMATION CRITERION TESTS FOR IDENTIFYING PROPER DISTRIBUTION OF MARGINALS
* ============================================================================
* Normal marginals
switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur success urbpercbefrev) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
estat ic
* Margin1 as t
switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur success urbpercbefrev) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(t) margin0(normal) margsel(normal)
estat ic
* Margin0 as t
switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur success urbpercbefrev) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(t) margsel(normal)
estat ic
* Margin0 as t and Margin1 as t (does not converge, must confine iterations to 11)
switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur success urbpercbefrev) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(t) margin0(t) margsel(normal) iterate(11)
estat ic
* Selection portion of model as logit
switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur success urbpercbefrev) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(logit)
estat ic
*	RESULT:  Normal marginal distributions are superior to any of the alternatives for all portions of the model


* +++++++++++++++++++++++++++++++++++++++++++
* CIVIL WAR REGIME PORTION OF SWITCHING MODEL
* +++++++++++++++++++++++++++++++++++++++++++
* ======================================================================
* SWITCHING REG: CHOOSING SPECIFICATIONS FOR CIVIL WAR REGIME--TABLE 8.2
* ======================================================================
* Model 1
switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal) 
quietly: switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur urbpercbefrev success) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
quietly: switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur) if startyear>1899 & e(sample), select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal) 
estat ic
* Model 2
switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur urbpercbefrev) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal) 
estat ic
* Model 3
switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur urbpercbefrev success) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
estat ic
* Model 4
switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur urbpercbefrev success newpolitymin1) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal) 
estat ic
* Model 5
switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur urbpercbefrev success lnpop) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
estat ic
* Model 6
switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur urbpercbefrev success ethnicorder) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
estat ic
* Model 7
switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur urbpercbefrev success leftist) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1 (fgm) margin1(normal) margin0(normal) margsel(normal)
estat ic
*
* Likelihood ratio tests to determine which model is more accurate
* Testing Model 3 vs. Model 4, Model 3 vs. Model 5
* Model 3
quietly: switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur urbpercbefrev success ) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
estimates store A
* Model 4
quietly: switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur urbpercbefrev success newpolitymin1) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal) 
estimates store B
quietly: switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur urbpercbefrev success lnpop) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal) 
estimates store C
* LR tests
* Model 4 vs. Model 3
lrtest A B
* 	RESULT:  LR chi2(1)=2.88, p=0.0899  Cannot conclude that Model 4 is superior to Model 3 at the .05 level
* Model 5 vs. Model 3
lrtest A C
* 	RESULT:  LR chi2(1)=3.56, p=0.0592  Cannot conclude that Model 5 is superior to Model 3 at the .05 level
* Model 3 is selected
drop _est_A _est_B _est_C
*
* ===========================================================
* SWITCHING REG: ESTIMATED CHANGE IN DEATHS DUE TO SHORTENED 
*   CIVIL WARS IN POST-COLD WAR PERIOD
* ===========================================================
* Full switching model
quietly: switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur success urbpercbefrev) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
tabstat lnmonthsdur if civilwar==1 & startyear>1899 & e(sample), s(mean) by(timeperiods) save
mat total1 = r(Stat2)
mat total2 = r(Stat3)
local newtot1 = total1[1,1]
display `newtot1'
local newtot2 = total2[1,1]
display `newtot2'
* Reassign var
local dur1 = `newtot1'
local dur2 = `newtot2'
* Calculate marginal effects for average duration for each period
* For checking the parameter to extract:  mat list e(b)
local param1 = e(k) - 2
matrix coefs = e(b)
local param2 = exp(coefs[1,`param1'])
margins, atmeans expression(exp((predict(xb1)+(0.5*(`param2')*(`param2'))))) at(lnmonthsdur=(`dur1' `dur2')) subpop(if civilwar==1)
* Calculate difference between marginal effects for each period
scalar m1 = el(r(b),1,1)
scalar m2 = el(r(b),1,2)
scalar mdiff = m2 - m1
display mdiff
* Calculate effect: Multiply effect times number of civil wars in post-Cold War period
tab timeperiods civilwar if startyear>1899, matcell(tper)
scalar cwnum = tper[3,2]
display cwnum
display mdiff * cwnum
* Drop scalars and macros
macro drop _all
scalar drop _all

* ==============================================================
* SWITCHING REG: ESTIMATED CHANGE IN DEATHS DUE TO URBANIZATION 
*   IN POST-COLD WAR PERIOD
* ==============================================================
* Full switching model
quietly: switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur success urbpercbefrev) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
tabstat urbpercbefrev if civilwar==1 & startyear>1899 & e(sample), s(mean) by(timeperiods) save
mat total1 = r(Stat2)
mat total2 = r(Stat3)
local newtot1 = total1[1,1]
display `newtot1'
local newtot2 = total2[1,1]
display `newtot2'
* Reassign var
local urb1 = `newtot1'
local urb2 = `newtot2'
* Calculate marginal effects for average level of urbanization for each period
* For checking the parameter to extract:  mat list e(b)
local param1 = e(k) - 2
matrix coefs = e(b)
local param2 = exp(coefs[1,`param1'])
margins, atmeans expression(exp((predict(xb1)+(0.5*(`param2')*(`param2'))))) at(urbpercbefrev=(`urb1' `urb2')) subpop(if civilwar==1)
* Calculate difference between marginal effects for each period
scalar m1 = el(r(b),1,1)
scalar m2 = el(r(b),1,2)
scalar mdiff = m2 - m1
display mdiff
* Calculate effect: Multiply effect times number of civil wars in post-Cold War period
tab timeperiods civilwar if startyear>1899, matcell(tper)
scalar cwnum = tper[3,2]
display cwnum
display mdiff * cwnum
* Drop scalars and macros
macro drop _all
scalar drop _all

* =================================================================
* SWITCHING REG:  ESTIMATED CHANGE IN DEATHS DUE TO CHANGING RATES 
*   OF OPPOSITION SUCCESS IN CIVIL WAR IN POST-COLD WAR PERIOD
* =================================================================
* Full switching model
quietly: switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur success urbpercbefrev) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
* Calculate marginal effects for opposition success
local param1 = e(k) - 2
matrix coefs = e(b)
local param2 = exp(coefs[1,`param1'])
margins, atmeans expression(exp((predict(xb1)+(0.5*(`param2')*(`param2'))))) at(success=(0 1)) subpop(if civilwar==1)
* Calculate difference between marginal effects for failed and successful revolutionary civil wars 
scalar m1 = el(r(b),1,1)
scalar m2 = el(r(b),1,2)
scalar mdiff = m2 - m1
display mdiff
* Calculate difference in number of conventional civil wars for each period
tab timeperiod success if civilwar==1 & startyear>1899, matcell(civsuc)
local cwnum2 = civsuc[2,2]
display `cwnum2'
local cwnum3 = civsuc[3,2]
display `cwnum3'
local cwnum4 = `cwnum3' - `cwnum2'
display `cwnum4'
* Calculate effect:  Multiply difference in number of successful civil wars by difference in marginal effects
display mdiff * `cwnum4'
* Drop scalars and macros
macro drop _all
scalar drop _all


* ++++++++++++++++++++++++++++++++++++
* SELECTION PORTION OF SWITCHING MODEL
* ++++++++++++++++++++++++++++++++++++
* ======================================================================================
* FIGURE 8.2, THE PROBABILITY THAT A REVOLUTIONARY EPIOSDE INVOLVED CIVIL WAR, OVER TIME
* ======================================================================================
logit civilwar c.startyear##c.startyear if startyear>1899, or
margins ,  at(startyear=(1900 1905 1910 1915 1920 1925 1930 1935 1940 1945 1950 1955 1960 1965 1970 1975 1980 1985 1990 1995 2000 2005 2010 2015))

* ====================================================================
* IDENTIFYING BEST SELECTION PORTION OF THE SWITCHING MODEL--TABLE 8.3
* ====================================================================
* Model 1
switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur success urbpercbefrev) if startyear>1899, select (civilwar =  urbandum) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
quietly: switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur success urbpercbefrev) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder newpolitymin1 newgdppcthl newlnoill diamonddum) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
quietly: switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur success urbpercbefrev) if startyear>1899 & e(sample), select (civilwar =  urbandum) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
estat ic
* Model 2
switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur success urbpercbefrev) if startyear>1899, select (civilwar =  urbandum ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
quietly: switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur success urbpercbefrev) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder newpolitymin1 newgdppcthl newlnoill diamonddum) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
quietly: switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur success urbpercbefrev) if startyear>1899 & e(sample), select (civilwar =  urbandum ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
estat ic
* Model 3
switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur success urbpercbefrev) if startyear>1899, select (civilwar =  urbandum ethnicorder leftist) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
quietly: switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur success urbpercbefrev) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder newpolitymin1 newgdppcthl newlnoill diamonddum) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
quietly: switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur success urbpercbefrev) if startyear>1899 & e(sample), select (civilwar =  urbandum ethnicorder leftist) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
estat ic
* Model 4
switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur success urbpercbefrev) if startyear>1899, select (civilwar =  urbandum ethnicorder leftist newpolitymin1) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
quietly: switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur success urbpercbefrev) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder newpolitymin1 newgdppcthl newlnoill diamonddum) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
quietly: switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur success urbpercbefrev) if startyear>1899 & e(sample), select (civilwar =  urbandum ethnicorder leftist newpolitymin1) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
estat ic
* Model 5
switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur success urbpercbefrev) if startyear>1899, select (civilwar =  urbandum ethnicorder leftist newgdppcthl) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
quietly: switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur success urbpercbefrev) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder newpolitymin1 newgdppcthl newlnoill diamonddum) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
quietly: switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur success urbpercbefrev) if startyear>1899 & e(sample), select (civilwar =  urbandum ethnicorder leftist newgdppcthl) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
estat ic
* Model 6
switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur success urbpercbefrev) if startyear>1899, select (civilwar =  urbandum ethnicorder leftist newlnoill diamonddum ) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
quietly: switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur success urbpercbefrev) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder newpolitymin1 newgdppcthl newlnoill diamonddum) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
quietly: switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur success urbpercbefrev) if startyear>1899 & e(sample), select (civilwar =  urbandum ethnicorder leftist newlnoill diamonddum) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
estat ic
* 	RESULT:  Model 3 is preferred

* Testing explanatory power of model 3
probit civilwar urbandum leftist ethnicorder if startyear>1899
estat classification
lroc , nograph

* ========================================
* EVALUATING IMPACT OF SELECTION PROCESSES
* ========================================
* ======================================================
* CALCULATE SELECTION EFFECT OF URBAN/RURAL LOCATION ON 
*    DEATHS IN CIVIL WARS AFTER COLD WAR
* ======================================================
* Run basic switching regression model
quietly: switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur success urbpercbefrev) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)

* Obtain marginal probabilities of selection into civil war for urban episodes
margins, atmeans expression(predict(psel)) at(urbandum=(0 1)) post
* Prob of not-urban-civic episode turning into civil war
scalar m1 = el(r(b),1,1)
* Prob of urban episode turning into civil war
scalar m2 = el(r(b),1,2)
* Prob of not-urban episode not involving civil war
scalar m3 = 1 - m1
* Prob of urban episode not involving civil war
scalar m4 = 1 - m2
display m1 " " m3 " " m2 " " m4

* Obtain number of urban and not-urban episodes for Cold War and post-Cold War periods
* Cold War and Post-Cold War urban episodes
tabstat urbandum if startyear>1899 & urbandum==1, s(count) by(timeperiods) nototal save
mat urbtotal1 = r(Stat2)
mat urbtotal2 = r(Stat3)
scalar numurbcold = urbtotal1[1,1]
scalar numurbpost = urbtotal2[1,1]
display numurbcold  " " numurbpost 
scalar urbdiff = numurbpost - numurbcold  
display urbdiff
* Cold War and Post-Cold War not-urban episodes
tabstat urbandum if startyear>1899 & urbandum==0, s(count) by(timeperiods) nototal save
mat urbtotal1 = r(Stat2)
mat urbtotal2 = r(Stat3)
scalar numnourbcold = urbtotal1[1,1]
scalar numnourbpost = urbtotal2[1,1]
display numnourbcold  " " numnourbpost 
scalar nourbdiff = numnourbpost - numnourbcold  
display nourbdiff

* Obtain differences in average deaths for urban and not-urban episodes involving and not involving civil war
* Average deaths in urban episodes with civil war
tabstat totaldeaths if  startyear>1949 & civilwar==1, s(mean) by(urbandum) save nototal
* Not-urban
mat total3 = r(Stat1)
local  newtot3 = total3[1,1]
scalar nourbcivdeaths = `newtot3'
* Urban 
mat total4 = r(Stat2)
local  newtot4 = total4[1,1]
scalar urbcivdeaths = `newtot4'
display nourbcivdeaths " " urbcivdeaths
scalar civdeathsdiff =  urbcivdeaths - nourbcivdeaths 
display civdeathsdiff 
* Average deaths in urban episodes without civil war
tabstat totaldeaths if  startyear>1949 & civilwar==0, s(mean) by(urbandum) save nototal
* Not-urban
mat total5 = r(Stat1)
local  newtot5 = total5[1,1]
scalar nourbnocivdeaths = `newtot5'
* Urban
mat total6 = r(Stat2)
local  newtot6 = total6[1,1]
scalar urbnocivdeaths = `newtot6'
display nourbnocivdeaths " " urbnocivdeaths
scalar nocivdeathsdiff =  urbnocivdeaths - nourbnocivdeaths 
display nocivdeathsdiff 

* Calculate increase/decrease in deaths as a result of selection into and out of civil war
* Increase/decrease in post-Cold War period in # deaths in urban episodes that selected into civil war
scalar a1 = (m2 * urbdiff * civdeathsdiff) 
if urbdiff < 0 & civdeathsdiff < 0 {
	scalar a1 = -1 * a1
	}
display a1
* Increase/decrease in post-Cold War period in # deaths in urban episodes that selected out of civil war
scalar a2 = (m4 * urbdiff * nocivdeathsdiff) 
if urbdiff < 0 & nocivdeathsdiff < 0 {
	scalar a2 = -1 * a2
	}
display a2
scalar totaleffect = a1 + a2 
display "The estimated effect on the number of deaths is " totaleffect
* Drop scalars and macros
macro drop _all
scalar drop _all

* ============================================================
* CALCULATE SELECTION EFFECT OF SOCIAL REVOLUTIONARY EPISODES 
*    ON DEATHS IN CIVIL WARS
* ============================================================
* Run basic switching regression model
quietly: switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur success urbpercbefrev) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)

* Obtain marginal probabilities of selection into civil war for social revolutionary episodes
margins, atmeans expression(predict(psel)) at(leftist=(0 1)) post
* Prob of not-leftist episode turning into civil war
scalar m1 = el(r(b),1,1)
* Prob of leftist episode turning into civil war
scalar m2 = el(r(b),1,2)
* Prob of not-leftist episode not involving civil war
scalar m3 = 1 - m1
* Prob of leftist not involving civil war
scalar m4 = 1 - m2
display m1 " " m3 " " m2 " " m4

* Obtain number of social revolutionary and not-social-revolutionary episodes for Cold War and post-Cold War periods
* Cold War and Post-Cold War social revolutionary episodes
tabstat leftist if startyear>1899 & leftist==1, s(count) by(timeperiods) nototal save
mat urbtotal1 = r(Stat2)
mat urbtotal2 = r(Stat3)
scalar numurbcold = urbtotal1[1,1]
scalar numurbpost = urbtotal2[1,1]
display numurbcold  " " numurbpost 
scalar urbdiff = numurbpost - numurbcold  
display urbdiff
* Cold War and Post-Cold War not-social revolutionary episodes
tabstat leftist if startyear>1899 & leftist==0, s(count) by(timeperiods) nototal save
mat urbtotal1 = r(Stat2)
mat urbtotal2 = r(Stat3)
scalar numnourbcold = urbtotal1[1,1]
scalar numnourbpost = urbtotal2[1,1]
display numnourbcold  " " numnourbpost 
scalar nourbdiff = numnourbpost - numnourbcold  
display nourbdiff

* Obtain differences in average deaths for social revolutionary and not-social-revolutionary episodes involving and not involving civil war
* Average deaths in revolutionary episodes with civil war
tabstat totaldeaths if  startyear>1949 & civilwar==1, s(mean) by(leftist) save nototal
* Not-leftist
mat total3 = r(Stat1)
local  newtot3 = total3[1,1]
scalar nourbcivdeaths = `newtot3'
* Leftist
mat total4 = r(Stat2)
local  newtot4 = total4[1,1]
scalar urbcivdeaths = `newtot4'
display nourbcivdeaths " " urbcivdeaths
scalar civdeathsdiff =  urbcivdeaths - nourbcivdeaths 
display civdeathsdiff 
* Average deaths in revolutionary episodes without civil war
tabstat totaldeaths if  startyear>1949 & civilwar==0, s(mean) by(leftist) save nototal
* Not leftist
mat total5 = r(Stat1)
local  newtot5 = total5[1,1]
scalar nourbnocivdeaths = `newtot5'
* Leftist
mat total6 = r(Stat2)
local  newtot6 = total6[1,1]
scalar urbnocivdeaths = `newtot6'
display nourbnocivdeaths " " urbnocivdeaths
scalar nocivdeathsdiff =  urbnocivdeaths - nourbnocivdeaths 
display nocivdeathsdiff 

* Calculate increase/decrease in deaths as a result of selection into and out of civil war
* Increase/decrease in post-Cold War period in # deaths in social revolutionary episodes that selected into civil war
scalar a1 = (m2 * urbdiff * civdeathsdiff) 
if urbdiff < 0 & civdeathsdiff < 0 {
	scalar a1 = -1 * a1
	}
display a1
* Increase/decrease in post-Cold War period in # deaths in social revolutionary episodes that selected out of civil war
scalar a2 = (m4 * urbdiff * nocivdeathsdiff) 
if urbdiff < 0 & nocivdeathsdiff < 0 {
	scalar a2 = -1 * a2
	}
display a2
scalar totaleffect = a1 + a2 
display "The estimated effect on the number of deaths is " totaleffect
* Drop scalars and macros
macro drop _all
scalar drop _all

* =========================================================
* CALCULATE SELECTION EFFECT OF EPISODES AIMED AT ALTERING 
*    ETHNIC/RACIAL ORDER ON DEATHS IN CIVIL WARS
* =========================================================
* Run basic switching regression model
quietly: switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur success urbpercbefrev) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)

* Obtain marginal probabilities of selection into civil war for ethnic/racial episodes
margins, atmeans expression(predict(psel)) at(ethnicorder=(0 1)) post
* Prob of not-ethnic/racial episode turning into civil war
scalar m1 = el(r(b),1,1)
* Prob of ethnic/racial episode turning into civil war
scalar m2 = el(r(b),1,2)
* Prob of not-ethnic/racial episode not involving civil war
scalar m3 = 1 - m1
* Prob of ethnic/racial episode not involving civil war
scalar m4 = 1 - m2
display m1 " " m3 " " m2 " " m4

* Obtain number of ethnic/racial and not-ethnic/racial episodes for Cold War and post-Cold War periods
* Cold War and Post-Cold War ethnic/racial episodes
tabstat ethnicorder if startyear>1899 & ethnicorder==1, s(count) by(timeperiods) nototal save
mat urbtotal1 = r(Stat2)
mat urbtotal2 = r(Stat3)
scalar numurbcold = urbtotal1[1,1]
scalar numurbpost = urbtotal2[1,1]
display numurbcold  " " numurbpost 
scalar urbdiff = numurbpost - numurbcold  
display urbdiff
* Cold War and Post-Cold War not-ethnic/racial episodes
tabstat ethnicorder if startyear>1899 & ethnicorder==0, s(count) by(timeperiods) nototal save
mat urbtotal1 = r(Stat2)
mat urbtotal2 = r(Stat3)
scalar numnourbcold = urbtotal1[1,1]
scalar numnourbpost = urbtotal2[1,1]
display numnourbcold  " " numnourbpost 
scalar nourbdiff = numnourbpost - numnourbcold  
display nourbdiff

* Obtain differences in average deaths for ethnic/racial and not-ethnic/racial revolutionary episodes involving and not involving civil war
* Average deaths in revolutionary episodes with civil war
tabstat totaldeaths if  startyear>1949 & civilwar==1, s(mean) by(ethnicorder) save nototal
* Not-ethnic/racial order
mat total3 = r(Stat1)
local  newtot3 = total3[1,1]
scalar nourbcivdeaths = `newtot3'
* Ethnic/racial order
mat total4 = r(Stat2)
local  newtot4 = total4[1,1]
scalar urbcivdeaths = `newtot4'
display nourbcivdeaths " " urbcivdeaths
scalar civdeathsdiff =  urbcivdeaths - nourbcivdeaths 
display civdeathsdiff 
* Average deaths in revolutionary episodes without civil war
tabstat totaldeaths if  startyear>1949 & civilwar==0, s(mean) by(ethnicorder) save nototal
* Not ethnic/racial order
mat total5 = r(Stat1)
local  newtot5 = total5[1,1]
scalar nourbnocivdeaths = `newtot5'
* Ethnic/racial order
mat total6 = r(Stat2)
local  newtot6 = total6[1,1]
scalar urbnocivdeaths = `newtot6'
display nourbnocivdeaths " " urbnocivdeaths
scalar nocivdeathsdiff =  urbnocivdeaths - nourbnocivdeaths 
display nocivdeathsdiff 

* Calculate increase/decrease in deaths as a result of selection into and out of civil war
* Increase/decrease in post-Cold War period in # deaths in ethnic/racial revolutionary episodes that selected into civil war
scalar a1 = (m2 * urbdiff * civdeathsdiff) 
if urbdiff < 0 & civdeathsdiff < 0 {
	scalar a1 = -1 * a1
	}
display a1
* Increase/decrease in post-Cold War period in # deaths in ethnic/racial revolutionary episodes that selected out of civil war
scalar a2 = (m4 * urbdiff * nocivdeathsdiff) 
if urbdiff < 0 & nocivdeathsdiff < 0 {
	scalar a2 = -1 * a2
	}
display a2
scalar totaleffect = a1 + a2 
display "The estimated effect on the number of deaths is " totaleffect
* Drop scalars and macros
macro drop _all
scalar drop _all


* ++++++++++++++++++++++++++++++++++++++++
* NO CIVIL WAR PORTION OF SWITCHING MODEL
* ++++++++++++++++++++++++++++++++++++++++
* =========================================================================
* SWITCHING REG: CHOOSING SPECIFICATIONS FOR NO CIVIL WAR REGIME--TABLE 8.4
* =========================================================================
* Model 1
switchcopula (lndeaths = urbandum ) (lndeaths =  lnmonthsdur urbpercbefrev success) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
quietly: switchcopula (lndeaths = urbandum urbancivic success newpolitymin1 newgdppcthl humanrightsrats startyear) (lndeaths =  lnmonthsdur urbpercbefrev success) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
quietly: switchcopula (lndeaths = urbandum ) (lndeaths =  lnmonthsdur urbpercbefrev success) if startyear>1899 & e(sample), select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
estat ic
* Model 2
switchcopula (lndeaths = urbandum urbancivic) (lndeaths =  lnmonthsdur urbpercbefrev success) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
quietly: switchcopula (lndeaths = urbandum urbancivic success newpolitymin1 newgdppcthl humanrightsrats startyear) (lndeaths =  lnmonthsdur urbpercbefrev success) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
quietly: switchcopula (lndeaths = urbandum urbancivic) (lndeaths =  lnmonthsdur urbpercbefrev success) if startyear>1899 & e(sample), select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
estat ic
* Model 3
switchcopula (lndeaths = urbandum urbancivic success) (lndeaths =  lnmonthsdur urbpercbefrev success) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
quietly: switchcopula (lndeaths = urbandum urbancivic success newpolitymin1 newgdppcthl humanrightsrats startyear) (lndeaths =  lnmonthsdur urbpercbefrev success) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
quietly: switchcopula (lndeaths = urbandum urbancivic success) (lndeaths =  lnmonthsdur urbpercbefrev success) if startyear>1899 & e(sample), select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
estat ic
* Model 4
switchcopula (lndeaths = urbandum urbancivic success newpolitymin1) (lndeaths =  lnmonthsdur urbpercbefrev success) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
quietly: switchcopula (lndeaths = urbandum urbancivic success newpolitymin1 newgdppcthl humanrightsrats startyear) (lndeaths =  lnmonthsdur urbpercbefrev success) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
quietly: switchcopula (lndeaths = urbandum urbancivic success newpolitymin1) (lndeaths =  lnmonthsdur urbpercbefrev success) if startyear>1899 & e(sample), select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
estat ic
* Model 5
switchcopula (lndeaths = urbandum urbancivic success newpolitymin1 newgdppcthl) (lndeaths =  lnmonthsdur urbpercbefrev success) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
quietly: switchcopula (lndeaths = urbandum urbancivic success newpolitymin1 newgdppcthl humanrightsrats startyear) (lndeaths =  lnmonthsdur urbpercbefrev success) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
quietly: switchcopula (lndeaths = urbandum urbancivic success newpolitymin1 newgdppcthl) (lndeaths =  lnmonthsdur urbpercbefrev success) if startyear>1899 & e(sample), select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
estat ic
* Model 6
switchcopula (lndeaths = urbandum urbancivic success newpolitymin1 newgdppcthl leftist) (lndeaths =  lnmonthsdur urbpercbefrev success) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
quietly: switchcopula (lndeaths = urbandum urbancivic success newpolitymin1 newgdppcthl humanrightsrats startyear) (lndeaths =  lnmonthsdur urbpercbefrev success) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
quietly: switchcopula (lndeaths = urbandum urbancivic success newpolitymin1 newgdppcthl leftist) (lndeaths =  lnmonthsdur urbpercbefrev success) if startyear>1899 & e(sample), select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
estat ic
* Model 7
switchcopula (lndeaths = urbandum urbancivic success newpolitymin1 newgdppcthl humanrightsrats startyear) (lndeaths =  lnmonthsdur urbpercbefrev success) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
quietly: switchcopula (lndeaths = urbandum urbancivic success newpolitymin1 newgdppcthl humanrightsrats startyear) (lndeaths =  lnmonthsdur urbpercbefrev success) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
quietly: switchcopula (lndeaths = urbandum urbancivic success newpolitymin1 newgdppcthl humanrightsrats startyear) (lndeaths =  lnmonthsdur urbpercbefrev success) if startyear>1899 & e(sample), select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
estat ic

* Likelihood ratio test of Models 5 and 6
quietly: switchcopula (lndeaths = urbandum urbancivic success newpolitymin1 newgdppcthl) (lndeaths =  lnmonthsdur urbpercbefrev success) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
estimates store A
quietly: switchcopula (lndeaths = urbandum urbancivic success newpolitymin1 newgdppcthl leftist) (lndeaths =  lnmonthsdur urbpercbefrev success) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
estimates store B
lrtest A B
* 	RESULT:  LR chi2(1)=2.26, p=0.1324  Cannot conclude that Model 6 is superior to Model 5 at the .05 level
drop _est_A _est_B 
*   RESULT: Model 5 is the preferred model

* GLM estimation of Model 5
quietly: switchcopula (lndeaths = urbandum newgdppcthl urbancivic success newpolitymin1) (lndeaths =  lnmonthsdur urbpercbefrev success) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
glm totaldeaths urbandum newgdppcthl urbancivic success newpolitymin1 if civilwar==0 & startyear>1899 & e(sample), link(log) family(gamma)


* ============================================================
* SWITCHING REG: ESTIMATED EFFECT ON DEATHS OF URBAN LOCATION 
*    IN EPISODES WITHOUT CIVIL WARS, 1985-2014 vs. 1900-1949 
* ============================================================
* Full switching model
quietly: switchcopula (lndeaths = urbandum urbancivic success newpolitymin1 newgdppcthl ) (lndeaths =  lnmonthsdur urbpercbefrev success) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
tabstat urbandum if civilwar==0 & startyear>1899, s(mean) by(timeperiods) save
mat total1 = r(Stat1)
mat total3 = r(Stat3)
local newtot1 = total1[1,1]
display `newtot1'
local newtot3 = total3[1,1]
display `newtot3'
* Reassign var
local lev1 = `newtot1'
local lev3 = `newtot3'
* Calculate marginal effects for success rates for each period
* For checking the parameter to extract:  mat list e(b)
local param1 = e(k) - 3
matrix coefs = e(b)
local param2 = exp(coefs[1,`param1'])
margins, atmeans expression(exp((predict(xb0)+(0.5*(`param2')*(`param2'))))) at(urbandum=(`lev1' `lev3')) subpop(if civilwar==0)
* Calculate difference between marginal effects for each period
scalar m1 = el(r(b),1,1)
scalar m3 = el(r(b),1,2)
* Calculate effect: Multiply effect times number of non-civil-war episodes in post-Cold War period
tab timeperiods civilwar if startyear>1899, matcell(tper)
scalar ncwnum1 = tper[1,1]
scalar ncwnum3 = tper[3,1]
display ncwnum1
display ncwnum3
scalar effper1 = m1 * ncwnum1
scalar effper3 = m3 * ncwnum3
display "The estimated effect on the number of deaths is " (effper3 - effper1)
* Drop scalars and macros
macro drop _all
scalar drop _all

* ====================================================================
* SWITCHING REG: ESTIMATED EFFECT ON DEATHS OF URBAN CIVIC REPERTOIRE 
*    IN EPISODES WITHOUT CIVIL WARS, 1985-2014 vs. 1900-1949 
* ====================================================================
* Full switching model
quietly: switchcopula (lndeaths = urbandum urbancivic success newpolitymin1 newgdppcthl) (lndeaths =  lnmonthsdur urbpercbefrev success) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
tabstat urbancivic if civilwar==0 & startyear>1899, s(mean) by(timeperiods) save
mat total1 = r(Stat1)
mat total3 = r(Stat3)
local newtot1 = total1[1,1]
display `newtot1'
local newtot3 = total3[1,1]
display `newtot3'
* Reassign var
local lev1 = `newtot1'
local lev3 = `newtot3'
* Calculate marginal effects for success rates for each period
* For checking the parameter to extract:  mat list e(b)
local param1 = e(k) - 3
matrix coefs = e(b)
local param2 = exp(coefs[1,`param1'])
margins, atmeans expression(exp((predict(xb0)+(0.5*(`param2')*(`param2'))))) at(urbancivic=(`lev1' `lev3')) subpop(if civilwar==0)
* Calculate difference between marginal effects for each period
scalar m1 = el(r(b),1,1)
scalar m3 = el(r(b),1,2)
* Calculate effect: Multiply effect times number of non-civil-war episodes in post-Cold War period
tab timeperiods civilwar if startyear>1899, matcell(tper)
scalar ncwnum1 = tper[1,1]
scalar ncwnum3 = tper[3,1]
display ncwnum1
display ncwnum3
scalar effper1 = m1 * ncwnum1
scalar effper3 = m3 * ncwnum3
display "The estimated effect on the number of deaths is " (effper3 - effper1)
* Drop scalars and macros
macro drop _all
scalar drop _all

* ===================================================================
* SWITCHING REG: ESTIMATED EFFECT ON DEATHS OF OPPOSITION SUCCESS IN 
*    EPISODES WITHOUT CIVIL WARS, 1985-2014 vs. 1900-1949 
* ===================================================================
* Full switching model
quietly: switchcopula (lndeaths = urbandum urbancivic success newpolitymin1 newgdppcthl) (lndeaths =  lnmonthsdur urbpercbefrev success) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
tabstat success if civilwar==0 & startyear>1899, s(mean) by(timeperiods) save
mat total1 = r(Stat1)
mat total3 = r(Stat3)
local newtot1 = total1[1,1]
display `newtot1'
local newtot3 = total3[1,1]
display `newtot3'
* Reassign var
local lev1 = `newtot1'
local lev3 = `newtot3'
* Calculate marginal effects for success rates for each period
* For checking the parameter to extract:  mat list e(b)
local param1 = e(k) - 3
matrix coefs = e(b)
local param2 = exp(coefs[1,`param1'])
margins, atmeans expression(exp((predict(xb0)+(0.5*(`param2')*(`param2'))))) at(success=(`lev1' `lev3')) subpop(if civilwar==0)
* Calculate difference between marginal effects for each period
scalar m1 = el(r(b),1,1)
scalar m3 = el(r(b),1,2)
* Calculate effect: Multiply effect times number of non-civil-war episodes in post-Cold War period
tab timeperiods civilwar if startyear>1899, matcell(tper)
scalar ncwnum1 = tper[1,1]
scalar ncwnum3 = tper[3,1]
display ncwnum1
display ncwnum3
scalar effper1 = m1 * ncwnum1
scalar effper3 = m3 * ncwnum3
display "The estimated effect on the number of deaths is " (effper3 - effper1)
* Drop scalars and macros
macro drop _all
scalar drop _all

* ==============================================================
* SWITCHING REG: ESTIMATED EFFECT ON DEATHS OF POLITY SCORES IN 
*    EPISODES WITHOUT CIVIL WARS, 1985-2014 vs. 1900-1949 
* ==============================================================
* Full switching model
quietly: switchcopula (lndeaths = urbandum urbancivic success newpolitymin1 newgdppcthl) (lndeaths =  lnmonthsdur urbpercbefrev success) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
tabstat newpolitymin1 if civilwar==0 & startyear>1899, s(mean) by(timeperiods) save
mat total1 = r(Stat1)
mat total3 = r(Stat3)
local newtot1 = total1[1,1]
display `newtot1'
local newtot3 = total3[1,1]
display `newtot3'
* Reassign var
local lev1 = `newtot1'
local lev3 = `newtot3'
* Calculate marginal effects for success rates for each period
* For checking the parameter to extract:  mat list e(b)
local param1 = e(k) - 3
matrix coefs = e(b)
local param2 = exp(coefs[1,`param1'])
margins, atmeans expression(exp((predict(xb0)+(0.5*(`param2')*(`param2'))))) at(newpolitymin1=(`lev1' `lev3')) subpop(if civilwar==0)
* Calculate difference between marginal effects for each period
scalar m1 = el(r(b),1,1)
scalar m3 = el(r(b),1,2)
* Calculate effect: Multiply effect times number of non-civil-war episodes in post-Cold War period
tab timeperiods civilwar if startyear>1899, matcell(tper)
scalar ncwnum1 = tper[1,1]
scalar ncwnum3 = tper[3,1]
display ncwnum1
display ncwnum3
scalar effper1 = m1 * ncwnum1
scalar effper3 = m3 * ncwnum3
display "The estimated effect on the number of deaths is " (effper3 - effper1)
* Drop scalars and macros
macro drop _all
scalar drop _all

* ============================================================
* SWITCHING REG: ESTIMATED EFFECT ON DEATHS OF GDP PER CAPITA 
*    IN EPISODES WITHOUT CIVIL WARS, 1985-2014 vs. 1900-1949 
* ============================================================
* Full switching model
quietly: switchcopula (lndeaths = urbandum urbancivic success newpolitymin1 newgdppcthl ) (lndeaths =  lnmonthsdur urbpercbefrev success) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(normal)
tabstat newgdppcthl if civilwar==0 & startyear>1899, s(mean) by(timeperiods) save
mat total1 = r(Stat1)
mat total3 = r(Stat3)
local newtot1 = total1[1,1]
display `newtot1'
local newtot3 = total3[1,1]
display `newtot3'
* Reassign var
local lev1 = `newtot1'
local lev3 = `newtot3'
* Calculate marginal effects for success rates for each period
* For checking the parameter to extract:  mat list e(b)
local param1 = e(k) - 3
matrix coefs = e(b)
local param2 = exp(coefs[1,`param1'])
margins, atmeans expression(exp((predict(xb0)+(0.5*(`param2')*(`param2'))))) at(newgdppcthl=(`lev1' `lev3')) subpop(if civilwar==0)
* Calculate difference between marginal effects for each period
scalar m1 = el(r(b),1,1)
scalar m3 = el(r(b),1,2)
* Calculate effect: Multiply effect times number of non-civil-war episodes in post-Cold War period
tab timeperiods civilwar if startyear>1899, matcell(tper)
scalar ncwnum1 = tper[1,1]
scalar ncwnum3 = tper[3,1]
display ncwnum1
display ncwnum3
scalar effper1 = m1 * ncwnum1
scalar effper3 = m3 * ncwnum3
display "The estimated effect on the number of deaths is " (effper3 - effper1)
* Drop scalars and macros
macro drop _all
scalar drop _all

* =================================================================
* SWITCHING REG: JACKKNIFE LEAVE-ONE-OUT CROSS-VALIDATION OF MODEL
* =================================================================
jacknife ,  cluster(revid): switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur success urbpercbefrev) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(logit) iterate(75)

* =============================================
* SWITCHING REG: BOOTSTRAP VALIDATION OF MODEL
* =============================================
bootstrap , reps(200) seed(1234): switchcopula (lndeaths = success newpolitymin1 urbancivic newgdppcthl urbandum) (lndeaths =  lnmonthsdur success urbpercbefrev) if startyear>1899, select (civilwar =  urbandum leftist ethnicorder) copula0(clayton) copula1(fgm) margin1(normal) margin0(normal) margsel(logit) iterate(75)


log close

clear

